import socket

def run():
    host = '127.0.0.1'
    port = 5000
    
    s = socket.socket()
    s.bind((host, port))    
    print "Server is ready"
    
    print 'Listening...'
    s.listen(1)        
    c, addr = s.accept()
    print 'connection...' + str(addr) 
    
    while True:
        data = c.recv(1024)
        if not data:
            break
        print 'from connected user : ' + str(data)
        data = str(data.upper())
        print 'sending : ' + str(data)
        c.send(str(data))
    c.close()

def runUDP():
    host = '127.0.0.1'
    port = 5000
    
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind((host, port))
    
    print 'Server is ready'
    
    while True:
        data, adr = s.recvfrom(1024)
        print 'Message from : ' + str(adr)
        print 'Content : ' + str(data)
        
        data = str(data.upper())
        
        s.sendto(data, adr)
    s.close()
        
def main():
    runUDP()
    
if __name__ == '__main__':
    main()